package com.focusai.efairy.ui.adapter.dev;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.focusai.efairy.R;
import com.focusai.efairy.model.dev.ImgAssistInfo;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;
import com.focusai.efairy.ui.widget.InputGirdImageView;
import com.focusai.efairy.utils.ActivityUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by luo_guangwen on 2017/8/30.
 */

public class DeviceInfoImgViewBinder extends ItemViewBinder<ImgAssistInfo, DeviceInfoImgViewBinder.ViewHolder> {

    private Context mContext;

    public DeviceInfoImgViewBinder(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_dev_info_img, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final ImgAssistInfo dataItem) {
        final InputGirdImageView girdImageView = holder.girdImageView;
        girdImageView.refreshDataNoAdd(dataItem.efairydevice_imgurl_list);
        girdImageView.getEditText().setVisibility(View.GONE);
        girdImageView.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseRecyclerViewHolder holder) {
                ActivityUtils.openPhotoPagerActivity((Activity) mContext, 100, girdImageView.getPosition(holder), dataItem.efairydevice_imgurl_list, false);
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        InputGirdImageView girdImageView;

        ViewHolder(View itemView) {
            super(itemView);
            girdImageView = (InputGirdImageView) itemView.findViewById(R.id.grid_img_view);
        }

    }
}
